<script setup>
import { ref } from 'vue'
import { useAdminStore } from '@/stores';
import { getHisTask } from '@/api/equipment/tactics'
import TreeSlideShow from '@/components/tree/TreeSlideShow.vue';
const adminStore = useAdminStore()
const task = ref([])
const taskloading = ref(false)
async function getNodeData(data) {
  taskloading.value = true
  console.log(data.id)
  // deptId.value = data.id
  await getHisTask(data.id).then(res => {
    task.value = res.data.data
    console.log('hisTask', task.value)
  })
  taskloading.value = false
}

</script>

<template>
  <el-row>
    <TreeSlideShow :list="adminStore.deptList" @getNodeData="getNodeData"></TreeSlideShow>
    <!-- <el-col :span="4" class="left">
      <el-input class="search" v-model="filterText" placeholder="关键词搜索" />
      <el-tree ref="treeRef" class="filter-tree" :props="{ children: 'children', label: 'label' }"
        :data="adminStore.deptList" node-key="id" default-expand-all :expand-on-click-node="false"
        :filter-node-method="filterNode" @node-click="showNodeData">
      </el-tree>
    </el-col> -->
    <el-col :span="20" class="right">
      <el-form :inline="true" size="small">
        <el-form-item>
          <el-select placeholder="任务类型"></el-select>
        </el-form-item>
        <el-form-item>
          <el-select placeholder="设备名称"></el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker placeholder="开始日期"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100px;" @click="search">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="taskloading" :data="task" fit>
        <el-table-column align="center" label-align="center" label="序号" type="index" width="55px"></el-table-column>
        <el-table-column align="center" label-align="center" label="任务名称" prop="tacticsName"></el-table-column>
        <el-table-column align="center" label-align="center" label="类型" width="80px">
          <template #default="{ row }">
            {{ row.code.substring(0, 2) === 'LC' ? '润滑' : (row.code.substring(0, 2) === 'MT' ? '保养' :
              (row.code.substring(0, 2) === 'SC' ? '点检' : '维修')) }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="设备名称" prop="deviceName"></el-table-column>
        <el-table-column align="center" label-align="center" label="任务编号" prop="code"></el-table-column>
        <el-table-column align="center" label-align="center" label="开始时间" prop="startDate"
          width="120px"></el-table-column>
        <el-table-column align="center" label-align="center" label="完成时间" prop="completedTime"
          width="120px"></el-table-column>
        <el-table-column align="center" label-align="center" label="完成情况" width="100px">
          <template #default="{ row }">
            <el-tag :type="row.completed === '1' ? 'success' : 'danger'" style="width:64px">{{ row.completed === '1' ?
              '已完成' :
              '未完成'
              }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label-align="center" label="异常情况" width="100px">
          <template #default="{ row }">
            <el-tag :type="row.result === '正常' ? 'success' : (row.result === '异常' ? 'danger' : 'warning')" effect="dark"
              style="width:56px">{{ row.result
              }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label-align="center" label="操作">
          <template #default="scope">
            <el-tooltip class="box-item" effect="dark" content="查看" placement="top-start">
              <el-button size="small" @click="handleView(scope.row)"><el-icon>
                  <View />
                </el-icon></el-button></el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
  </el-row>

</template>

<style scoped lang="less">
.right {
  padding-left: 30px;

  .el-select {
    width: 210px;
  }
}

:deep(th.el-table__cell) {
  background-color: var(--el-color-primary-light-7) !important;
}
</style>